//
//  NoticeInfoViewController+Request.m
//  NaRiLSVMT
//
//  Created by jmsre on 14-9-4.
//  Copyright (c) 2014年 helloyouth.org. All rights reserved.
//

#import "NoticeInfoViewController+Request.h"
#import "MBProgressController.h"
#import "Network_Operation.h"

@implementation NoticeInfoViewController (Request)



-(void)NRLSMTGetTemplateInfo
{
    [[MBProgressController sharedInstance] showWithText:@"正在努力加载..."];
    WeakSelf;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *getTemplateInfo = [Network_API Network_API_GetTemplateInfo];
        
        AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getTemplateInfo];
        NSString    *str = [NSString stringWithFormat:@"[{\"classname\":%@,\"methodname\":%@,\"parameterClasss\":[{\"parametername\":%@,\"parametervalue\":\"%@\",\"valuetype\":%@},{\"parametername\":%@,\"parametervalue\":\"%@\",\"valuetype\":%@}]}]",@"\"iControlSolutionService\"",@"\"getTemplateInfo\"",@"\"screenId\"",wself.screenId,@"\"java.lang.String\"",@"\"templateId\"",wself.templateId,@"\"java.lang.String\""];
        [httpClient postPath:getTemplateInfo
                  parameters:@{@"jsonstr":str,
                               @"callback":@""
                               }
                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                         if([responseObject isKindOfClass:[NSString class]])
                         {
                             NSString *resStr = [NSString stringWithString:responseObject];
                             if(!([resStr rangeOfString:@"info"].location == NSNotFound))
                             {
                                 NSLog(@"getTemplateInfo Success");
                                 
                                 
                                 wself.recieveData = [NSMutableArray arrayWithArray:[Common jsontoArr:resStr]];
                                 
                                 NSDictionary *dic = [wself.recieveData objectAtIndex:0];
                                 
                                 if ([dic objectForKey:@"info"] != [NSNull null]) {
                                     NSString *resultStr = [dic objectForKey:@"info"];
                                     
                                     
                                     NSString *tmpString = resultStr;
                                     
                                     
                                     CGSize s = [tmpString sizeWithFont:wself.noticeMainContent.font
                                                      constrainedToSize:Size(wself.noticeMainContent.frame.Width, MAXFLOAT)
                                                          lineBreakMode:NSLineBreakByCharWrapping];
                                     if (s.height > wself.noticeMainContent.frame.Height) {
                                         double dHeight = s.height - wself.noticeMainContent.frame.Height;
                                         
                                         CGRect f = wself.noticeMainContent.frame;
                                         f.Height += dHeight;
                                         wself.noticeMainContent.frame = f;
                                         //
                                         //                                         f = self.underAxisImage.frame;
                                         //                                         f.Height += voteItemMaxHeight -40;
                                         //                                         self.underAxisImage.frame = f;
                                         //
                                         //                                         f = self.frame;
                                         //                                         f.Height += dHeight;
                                         //                                         self.frame = f;
                                     }
                                     wself.noticeMainContent.text = tmpString;
                                 }
                                 else{

                                     wself.noticeMainContent.text = @"";
                                 }
                             }
                             else
                             {
                                 dispatch_async(dispatch_get_main_queue(), ^{
                                //     self.navigationController.navigationBar.hidden = YES;
                                     [[MBProgressController sharedInstance] hide];
                                     [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕信息失败" AndDelay:1.5];
                                 });
                                 NSLog(@"直接返回");
                             }
                         }
                         else {
                             dispatch_async(dispatch_get_main_queue(), ^{
                              //   self.navigationController.navigationBar.hidden = YES;
                                 [[MBProgressController sharedInstance] hide];
                                 [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕信息失败"
                                                                                AndDelay:1.5];
                             });
                             NSLog(@"直接返回");
                         }
                     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                         dispatch_async(dispatch_get_main_queue(), ^{
                           //  self.navigationController.navigationBar.hidden = YES;
                             [[MBProgressController sharedInstance] hide];
                             [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕信息失败"
                                                                            AndDelay:1.5];
                         });
                     }];
    });
    [[MBProgressController sharedInstance] hide];
}


@end
